import requests
import random
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5
from Crypto.Signature import PKCS1_v1_5 as Signature_pkcs1_v1_5
import base64

 
def get_random_imei():
    num = str(random.randint(10000000000000, 99999999999999))
    num_list = list(num)
    math_sum = 0
    for i in range(1, len(num_list)+1):
        if i % 2 == 0:
            take_two_num = int(num_list[i-1]) * 2
            if len(str(take_two_num)) == 2:
                for j in list(str(take_two_num)):
                    math_sum = int(j) + math_sum
            else:
                math_sum = take_two_num + math_sum
        else:
            math_sum = int(num_list[i-1]) + math_sum
    last_num = list(str(math_sum))[-1]
    if last_num == 0:
        check_num = 0
        imei = num + str(check_num)
        return imei
    else:
        check_num = 10 - int(last_num)
        imei = num + str(check_num)
        return imei


pubKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALLUiZV6DVmAcJGOsWzftnYxDVpIdTlQynYeTtq5Z1ZzUteINPX24GyeetbYjnIT8pq0IdXGEjjBtngvddR0YaMCAwEAAQ==";
pubKey = "-----BEGIN PUBLIC KEY-----\n"+pubKey+"\n-----END PUBLIC KEY-----";

headers = {
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) \
    AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36','Token': '123456'}
r = requests.get('https://tcdn-api.itouchtv.cn/getParam', headers=headers)

node = r.json()["node"]
channel_list_url = 'https://api.itouchtv.cn/liveservice/v3/tvChannelList?node={0}'.format(node)

print(channel_list_url)

r = requests.get(channel_list_url, headers=headers)


print(get_random_imei())